package sceneGraph;

import javax.vecmath.*;

public class PlanetTriangle implements ISceneObject {

	private Point3f v1;
	private Point3f v2;
	private Point3f v3;

	private Vector3f n1;
	private Vector3f n2;
	private Vector3f n3;

	public PlanetTriangle(Point3f v1, Point3f v2, Point3f v3) {
		this.v1 = v1;
		this.v2 = v2;
		this.v3 = v3;
	}

	@Override
	public void accept(Visitor visitor) {
		visitor.visit(this);
	}

	public Point3f getVertex1() {
		return v1;
	}

	public Point3f getVertex2() {
		return v2;
	}

	public Point3f getVertex3() {
		return v3;
	}

	public Vector3f getNormal() {
		// getNormal must be dynamic as triangles points might be changed during its life!
		Vector3f normal;

		Vector3f vec1 = new Vector3f();
		vec1.sub(v1, v2);
		Vector3f vec2 = new Vector3f();
		vec2.sub(v1, v3);
		normal = new Vector3f(v1);
		normal.cross(vec2, vec1);
		normal.normalize();

		return normal;
	}

	public void setNormals(Vector3f n1, Vector3f n2, Vector3f n3) {
		this.n1 = n1;
		this.n2 = n2;
		this.n3 = n3;
	}

	public Vector3f getNormal1() {
		return n1;
	}

	public Vector3f getNormal2() {
		return n2;
	}

	public Vector3f getNormal3() {
		return n3;
	}
}
